<?php

namespace app\index\controller;


use think\Db;
use think\Request;
use think\View;
use app\index\model\Mood as mMood;

class Mood extends Base
{

    /*列表页*/
    public function index(Request $request)
    {

        //每页显示多少条
        $limit = $this->systemConfig['other_setting']['mood_page'];
        //当前是第几页
        $page = 1;

        //是否是分页跳转  每页显示多少条
        $limit = $request->isGet() && $request->has('limit') ? $request->param('limit') : $limit;
        //是否有参数  当前是第几页
        $page = $request->isGet() && $request->has('page') ? $request->param('page') : $page;


        $data = mMood::mAll($page,$limit);
//        halt($data);
        $this->assign(['data' => $data]);

        return view();
    }

    /*详情页*/
    public function detail(Request $request)
    {
        if ($request->isGet() && $request->has('id')) {
            //有人访问时，点击数自增1
            Db::name('mood')->where('id', $request->param('id'))->setInc('hits');

            //是否是分页跳转  每页显示多少条
            $limit = $request->isGet() && $request->has('limit') ? $request->param('limit') : 1;
            //是否有参数  当前是第几页
            $page = $request->isGet() && $request->has('page') ? $request->param('page') : 1;

            //获取当前ID文章内容
            $data['detail'] = mMood::read($request->param('id'),$page,$limit);
            //文章内容留言分页数据调用
            $message = $data['detail']['messages'];
            unset($data['detail']['messages']);
//            halt($data);
            $this->assign('data', $message);

            //获取上
            return $this->fetch('', $data);
        } else {
            return $this->error('请求参数错误', '/mood.html');
        }

    }


}
